package com.fwtai.api.controller;

import com.fwtai.config.ConfigFile;
import com.fwtai.service.api.UploadService;
import com.fwtai.tool.ToolClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件上传处理控制层|路由层[api]
*/
@RestController
@Api(tags = "文件上传处理,token必填",description = "图片|文件|证件|附件上传处理")
@RequestMapping(ConfigFile.api_v10 + "upload")
public class UploadController{

  private final UploadService uploadService;

  public UploadController(final UploadService uploadService){
    this.uploadService = uploadService;
  }

  /**
   * 处理身份证人像面、国徽面的上传
  */
  @ApiOperation(value = "处理身份证人像面、国徽面的上传,token必填", notes = "单独的处理身份证人像面、国徽面的上传")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "img_front", value = "身份证人像面,小程序端限制单个文件不能大于4MB", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "img_reverse", value = "身份证国徽面,小程序端限制单个文件不能大于4MB", dataType = "String", paramType = "query", required = true)
  })
  @PostMapping("/idCard")
  public void idCard(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(uploadService.idCard(request),response);
  }

  //处理门店申请时的协议图片的上传
  @ApiOperation(value = "处理门店申请时的协议图片的上传,token必填", notes = "单独的处理门店申请时的协议图片的上传")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "protocol", value = "处理门店申请时的协议图片的上传,小程序端限制单个文件不能大于4MB", dataType = "String", paramType = "query", required = true)
  })
  @PostMapping("/protocol")
  public void protocol(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(uploadService.protocol(request),response);
  }

  /**
   * 处理营业执照的上传
  */
  @ApiOperation(value = "处理营业执照的上传,token必填", notes = "处理营业执照的上传")
  @ApiImplicitParam(name = "license", value = "营业执照,小程序端限制文件不能大于6MB", dataType = "String", paramType = "query", required = true)
  @PostMapping("/license")
  public void license(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(uploadService.license(request),response);
  }
}